//
//  DFCommand.m
//  dfutil
//
//  Created by Tom Booth on 25/06/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "DFCommand.h"


@implementation DFCommand

@synthesize returnsRows;
@synthesize createsRows;
@synthesize name;
@synthesize description;


- initWithXML:(NSXMLElement*) xml {
	self = [super init];
	
	//NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	// fill the basic command class
	self.name  = [[xml attributeForName:@"name"] stringValue];
	
	self.description = [[[xml nodesForXPath:[NSString stringWithFormat:@"%@%@",[xml XPath],@"//description"] error:NULL] objectAtIndex:0] stringValue];
	self.returnsRows = [DFUtility boolifyString:[[[xml nodesForXPath:[NSString stringWithFormat:@"%@%@",[xml XPath],@"//returnsrows"] error:NULL] objectAtIndex:0] stringValue]];
	self.createsRows = [DFUtility boolifyString:[[[xml nodesForXPath:[NSString stringWithFormat:@"%@%@",[xml XPath],@"//createsrows"] error:NULL] objectAtIndex:0] stringValue]];
	
	// get the parameters
	NSArray *params = [xml nodesForXPath:[NSString stringWithFormat:@"%@%@",[xml XPath],@"//parameter"] error:NULL];
	for (NSXMLElement *parameter in params) {
		[parameters addObject:[[DFParameter alloc] initWithXML:parameter]];
	}

	// get the return parameters
	params = [xml nodesForXPath:[NSString stringWithFormat:@"%@%@",[xml XPath],@"//responsevalue"] error:NULL];
	for (NSXMLElement *parameter in params) {
		[returnParameters addObject:[[DFParameter alloc] initWithXML:parameter]];
	}
	
	//[pool drain];
	
	return self;
}

@end
